<?php
/**
 * Created by PhpStorm.
 * User: 84071
 * Date: 2018-08-07
 * Time: 15:33
 */
namespace app\common\model;
use think\Model;
class OrderMake extends Model{
// 开启自动写入时间戳
    protected $autoWriteTimestamp = true;
    protected $insert = ['addtime','addip'];
    protected $type = [
        'addtime'    => 'timestamp',
    ];
// 定义时间戳字段名
    protected $createTime = 'addtime';
    protected $updateTime = false;
    protected function setAddipAttr(){
        return request()->ip();
    }
    // 启用状态
    protected function getstatuszhAttr($value,$data){
        $status = [ 0 => '<a class="button button-S bg-yellow">等待平台确认</a>',1 => '<a class="button button-S bg-blue">等待老师上门</a>',2 => '<a class="button button-S">课程结束</a>',3 => '<a class="button button-S">申请取消</a>',4 => '<a class="button button-S">已取消</a>'];
        return $status[$data['status']];
    }
    // 老师订单状态
    protected function getvipstatuszhAttr($value,$data){
        $vipstatus = [ 0 => '<a class="button button-S bg-yellow">等待确认</a>',1 => '<a class="button button-S bg-blue">确认接单</a>',2 => '<a class="button button-S">课程结束</a>',3 => '<a class="button button-S">拒单</a>'];
        return $vipstatus[$data['vipstatus']];
    }
    public function get_one($data,$cha = true){
        //  检测是否需要获取订单信息
        if($cha){
            $ordermodel = new Order();
            $data = $ordermodel->get_list($data);
        }
        //  开始查询预约数量
        $shop = $data['conf'];
        foreach ($shop['shop'] as $k => $v){
            $v['makenum'] = $this->where('oid',$data['oid'])->where('aid',$v['aid'])->where('status','<>','4')->count();
            $shop['shop'][$k] = $v;
        }
        $data['conf'] = $shop;
        return $data;
    }
    //  获取接下来一周的课程详情
    public function get_maketable($data){
        $parttime['ktime'] = strtotime(date("Y-m-d 00:00:00",time()));
        $parttime['endtime'] = strtotime(date("Y-m-d 23:59:59",strtotime("7 day")));
        $list = $this->where('vipuid',$data['vip'])->where('maketime','>',$parttime['ktime'])->where('maketime','<',$parttime['endtime'])->where('status','in','1,2')->where('vipstatus','in','0,1,2')->order('maketime asc')->select();
        if(empty($list)){
            return false;
        }
        $newlist = null;
        foreach ($list as $k => $v){
            $v = $v->toArray();
            $v['time_Y']=date("Y",$v['maketime']);
            $v['time_m']=date("m",$v['maketime']);
            $v['time_d']=date("d",$v['maketime']);
            $v['time_H']=date("H",$v['maketime']);
            $v['time_i']=date("i",$v['maketime']);
            $v['time_s']=date("s",$v['maketime']);
            $v['maketime'] = date("Y-m-d H:i:s",$v['maketime']);
            $v['arttitle'] = \model('Article')->where('aid',$v['aid'])->value('title');
            $v['useraddress'] = \model('UserAddress')->where('id',$v['resid'])->find();
            $newlist[$k] = $v;
        }
        return $newlist;
    }

}